﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace com.sharepointutils.application
{
    class ErrorList : System.Windows.Forms.ListView
    {

        ColumnHeader EventType = new ColumnHeader();
        ColumnHeader EventID = new ColumnHeader();
        ColumnHeader Source = new ColumnHeader();
        ColumnHeader Log = new ColumnHeader();
        ColumnHeader DateTimeStamp = new ColumnHeader();

        public ErrorList()
        {
            this.EventType.Name = "EventType";
            this.EventType.Text = "Event Type";

            this.EventID.Name = "EventID";
            EventID.Text = "Event ID";

            this.Source.Name = "Source";
            Source.Text = "Source";

            this.Log.Name = "Log";
            Log.Text = "Log";

            this.DateTimeStamp.Name = "Time";
            DateTimeStamp.Text = "Time";

            this.HeaderStyle = ColumnHeaderStyle.Clickable;
            this.View = System.Windows.Forms.View.Details;
            this.AllowColumnReorder = true;
            this.Columns.AddRange(new ColumnHeader[] { 
            this.EventType,
            this.EventID,
            this.Source,
            this.Log,
            this.DateTimeStamp});
        }

        private int errorID = 0;

        public void ClearLog()
        {
            this.Items.Clear();
        }

        public void AddError(Exception ex)
        {
            errorID++;
            ListViewItem i = new ListViewItem (new String[] { "Error", errorID.ToString(), ex.Message , ex.StackTrace, DateTime.Now.ToString() });
            i.Tag = ex;
            this.Items.Add(i);
        }


    }
}
